import { DirectionCode, KeyEventParameters, SceneUtils, TButton, TLayout } from "../SceneControl";
import MainPageScene from "./MainPageScene";

const { ccclass, property } = cc._decorator;

@ccclass
export default class MilitaryPanelViewScene extends MainPageScene {


    @property(cc.Node)
    leftNode: cc.Node = null;

    @property(cc.Node)
    rightNode: cc.Node = null;

    getUpLayout(): TLayout {
        let layout = new TLayout();
        layout.buttonList = this.btns;
        layout.site.row = layout.buttonList.length - 1;
        return layout;
    }


    onKeyDown(para: KeyEventParameters) {
        if (para.DirectionCode == DirectionCode.LEFT) {
            SceneUtils.emitButton(this.leftNode);
        } else if (para.DirectionCode == DirectionCode.RIGHT) {
            SceneUtils.emitButton(this.rightNode);
        }
    }

    public get btns(): TButton[][] {
        let content = cc.find("New Node/scrollView/view/content", this.node);
        let btns = content.children.map(item => {
            let row = new TButton(item.getComponentInChildren(cc.Button).node);
            row.addKeyDownEvent(this.onKeyDown.bind(this))
            return [row]
        });
        return btns;
    }


}
